var prefix = "/basTeaching";

$(".form_datetime").datetimepicker({
    format: "yyyy-mm-dd hh:ii:ss",
    autoclose: true,//选择后是否自动关闭
    minView: 0,
    minuteStep: 1,
    todayBtn: true,
    language:'zh-CN',
    pickerPosition:"bottom-left"
});

// $(function(){
//     //初始化下列框
//     select2CommonAsync("#tCode","/select2/getStaffPCode.do","人员姓名/首字母",null,null);
//     select2CommonAsync("#sCode","/select2/getStaffPCode.do","人员姓名/首字母",null,null);
//     //初始化验证器
//     initValidator();
//     $('#tCode').on('change',function(){
//         $('#exampleForm').data('bootstrapValidator')
//             .updateStatus('sCode', 'NOT_VALIDATED', null)
//             .validateField('sCode');
//     }); // Notify only Select2 of changes
//     $('#sCode').on('change',function(){
//         $('#exampleForm').data('bootstrapValidator')
//             .updateStatus('tCode', 'NOT_VALIDATED', null)
//             .validateField('tCode');
//     }); // Notify only Select2 of changes
// });


//保存
function save(){
    // $("#exampleForm").data('bootstrapValidator').validate();//触发一次所有的验证
    // if(!$("#exampleForm").data('bootstrapValidator').isValid()){//判断验证是否已经通过
    //     return;
    // }
    $.ajax({
        cache : true,
        type : "POST",
        url : prefix + "/save.do",
        data : $("#exampleForm").serialize(),
        error : function(request) {
            toastr.error("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.toastr.success("操作成功");
                parent.reload();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                toastr.warning(data.msg)
            }
        }
    });
}

//初始化验证规则
function initValidator(){
    $('#exampleForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            tCode: {
                message: '人员A不能为空',
                validators: {
                    notEmpty: {
                        message: '此项不能为空'
                    },
                    different: {
                        field: 'sCode',
                        message: '不能同人员B相同'
                    }
                }
            },
            sCode: {
                message: '人员B不能为空',
                validators: {
                    notEmpty: {
                        message: '此项不能为空'
                    },
                    different: {
                        field: 'tCode',
                        message: '不能同人员A相同'
                    }
                }
            }
        }
    });
}